package site.wuao.simplerxjava.operator;

import android.util.Log;
import android.view.View;

import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func2;

/**
 * 操作符
 *
 * @author wuao
 * @date 2017/11/29
 * @github {https://github.com/CoderWuao}
 * @blogs {http://wuao.site/}
 * @note -
 * ---------------------------------------------------------------------------------------------------------------------
 * @modified -
 * @date -
 * @github -
 * @blogs -
 * @note -
 */
public class Operator {
    /** 标记 */
    private static final String TAG = "Operator";



    /**
     * takeLast
     *
     * @note
     */
    public static void takeLast() {
        Observable
                .just(1, 2, 3, 4, 5)
                .takeLast(3)
                .subscribe(new Action1<Integer>() {
                    @Override
                    public void call(Integer i) {
                        Log.i(TAG, "call: " + i);
                    }
                });
    }

    public void scan(View view) {
        Observable
                .just(1, 2, 3, 4)
                .scan(new Func2<Integer, Integer, Integer>() {
                    @Override
                    public Integer call(Integer integer, Integer integer2) {
                        return integer + integer2;
                    }
                })
                .subscribe(new Action1<Integer>() {
                    @Override
                    public void call(Integer i) {
                        Log.i(TAG, "call: " + i);
                    }
                });
    }
}
